package nsoft.swing.container;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

import nsoft.swing.component.NTextField;

public class NInputFieldPanel extends JPanel {

	/**
	 * serialVersionUID = 1L
	 */
	private static final long serialVersionUID = 1L;

	private GridBagConstraints constraints;

	public NInputFieldPanel() {
		this.setLayout(new GridBagLayout());
		this.constraints = new GridBagConstraints(0, 0, 1, 1, 0.5, 0.5,
				GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,
						0, 0, 0), 0, 0);
	}

	public void addField(Object bean, String property, String label,
			GridBagConstraints constraints) {
		add(new JLabel(label), constraints);
		constraints.gridx++;
		add(createComponent(bean, property), constraints);
	}

	public void addField(Object bean, String property, String label, int row,
			int column) {
		this.constraints.gridy = row;
		this.constraints.gridx = column;
		addField(bean, property, label, this.constraints);
	}

	public void addComponent(JComponent component, int row, int column) {
		this.constraints.gridy = row;
		this.constraints.gridx = column;
		add(component, constraints);
	}

	private JComponent createComponent(Object bean, String property) {
		return new NTextField(bean, property);
	}

}
